package com.smart.wap.app;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.ObjectUtil;
import com.smart.common.entities.ajax.AjaxResult;
import com.smart.common.entities.constant.SmartConstant;
import com.smart.common.entities.core.BaseSearch;
import com.smart.common.entities.core.Page;
import com.smart.common.entities.domain.OrderAddress;
import com.smart.manager.member.entities.models.MemberProfileAccount;
import com.smart.manager.member.entities.views.MemberView;
import com.smart.manager.member.repository.MemberAccountRepository;
import com.smart.manager.member.repository.MemberProfileAddressRepository;
import com.smart.manager.union.egg.enums.EggOrderState;
import com.smart.manager.union.egg.models.UnionEggOrder;
import com.smart.manager.union.egg.models.UnionEggProduct;
import com.smart.manager.union.egg.repository.UnionEggOrderRepository;
import com.smart.manager.union.egg.repository.UnionEggProductRepository;
import com.smart.utils.MemberAcl;
import com.smart.utils.MemberStp;
import com.smart.wap.bodys.EggOrderNotice;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.List;


/**
 * @author Administrator
 */

@Api(tags = "移动端-狼山土鸡蛋")
@RestController
@Log4j2
@RequestMapping(SmartConstant.WAP_API_PREFIX + "app/egg")
@RequiredArgsConstructor
public class EggController {

    private final UnionEggProductRepository productRepository;
    private final UnionEggOrderRepository orderRepository;

    @ApiOperation(value = "获取兑换规格")
    @GetMapping(value = "getProductList")
    @SaCheckLogin(type = MemberStp.TYPE)
    public AjaxResult<List<UnionEggProduct>> getProductList() {
        List<UnionEggProduct> result = productRepository.getList();
        return AjaxResult.data(result);
    }


    @ApiOperation(value = "创建兑蛋订单")
    @GetMapping(value = "createOrder/{productId}")
    @SaCheckLogin(type = MemberStp.TYPE)
    public AjaxResult<String> createOrder(@PathVariable Long productId) {
        Long memberId = MemberAcl.getLoginId();
        orderRepository.createOrder(memberId, productId);
        return AjaxResult.success();
    }


    @ApiOperation(value = "获取我提蛋订单")
    @GetMapping(value = "getMyOrderList")
    @SaCheckLogin(type = MemberStp.TYPE)
    public AjaxResult<Page<UnionEggOrder>> getMyOrderList(@Validated BaseSearch baseSearch) {
        Long memberId = MemberAcl.getLoginId();
        Page<UnionEggOrder> result = orderRepository.getMyPageList(memberId, baseSearch);
        return AjaxResult.data(result);
    }



    @ApiOperation(value = "获取最新N条鸡蛋提取记录")
    @GetMapping(value = "getLastOrder")
    @SaCheckLogin(type = MemberStp.TYPE)
    public AjaxResult<List<EggOrderNotice>> getLastOrder( Integer size) {
        List<EggOrderNotice> result = orderRepository.getLastOrder( size);
        return AjaxResult.data(result);
    }

}
